import { FrameTimer } from "../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../com/gengine/core/frame/TimerType";
import { RollTipsItem } from "../view/msgbroad/RollTipsItem";
import { LayerManager } from "./LayerManager";
import { ObjectPool } from "../../../com/gengine/utils/pools/ObjectPool";
import { Global } from "../../../com/gengine/global/Global";
type int = number;
//class MsgRollTipsImpl
    
    export  class MsgRollTipsImpl /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._msgs = [];
            this._shows = [];
            mouseEnabled = false;
            mouseChildren = false;
            return;
        }

        /* internal  */startShowTips(): void
        {
            if (!this._timer) 
            {
                this._timer = new FrameTimer(1);
            }
            this._timer.addListener(TimerType.ENTERFRAME, this.frameScript);
            if (!this._timer.running) 
            {
                this._timer.reset();
                this._timer.start();
            }
            return;
        }

        /* internal  */stopShowTips(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.dispose();
                this._timer.isDelete = false;
            }
            return;
        }

        /* internal  */showRollTips(arg1: RollTipsItem): void
        {
            if (!this.parent) 
            {
                LayerManager.msgTipLayer.addChild(this);
                this.stageResize();
            }
            this.addChild(arg1);
            return;
        }

        /* internal  */hideRollTips(): void
        {
            if (this.parent) 
            {
                this.parent.removeChild(this);
            }
            return;
        }

        public get msgLength(): int
        {
            return this._msgs.length + this._shows.length;
        }

        /* internal  */frameScript(arg1: FrameTimer): void
        {
            var loc1=null;
            var loc2=null;
            if (this._shows.length > 0 && this.inPeriod) 
            {
                var loc3;
                var loc4=((loc3 = this)._periodCount + 1);
                loc3._periodCount = loc4;
                return;
            }
            this._periodCount = 0;
            if (this._msgs.length > 0) 
            {
                this.clearTimeOut();
                loc1 = this._msgs.shift();
                loc2 = ObjectPool.getObject(RollTipsItem);
                loc2.updateData(loc1, this.onInEnd);
                this.showRollTips(loc2);
                this._shows.push(loc1);
            }
            else 
            {
                this.stopShowTips();
            }
            return;
        }

        /* internal  */clearTimeOut(): void
        {
            this._childIndex = 0;
            this._childLength = numChildren;
            while (this._childIndex < this._childLength) 
            {
                (getChildAt(this._childIndex) as RollTipsItem).clearTimeOut();
                var loc1;
                var loc2=((loc1 = this)._childIndex + 1);
                loc1._childIndex = loc2;
            }
            return;
        }

        /* internal  */onInEnd(arg1: RollTipsItem): void
        {
            this._shows.shift();
            if (arg1.parent) 
            {
                arg1.parent.removeChild(arg1);
            }
            arg1.dispose();
            ObjectPool.disposeObject(arg1, RollTipsItem);
            return;
        }

        public showMsg(arg1: string): void
        {
            var loc1=null;
            this._periodTotal = 12;
            if (this._msgs.length > 0) 
            {
                loc1 = this._msgs[0];
                if (loc1 == arg1) 
                {
                    return;
                }
                if (this._shows.length > 0) 
                {
                    loc1 = this._shows[0];
                    if (loc1 == arg1 && this.inPeriod) 
                    {
                        return;
                    }
                }
                if (this.msgLength > 8) 
                {
                    this._periodTotal = 6;
                }
                this._msgs.push(arg1);
            }
            else 
            {
                this._msgs.push(arg1);
            }
            this.startShowTips();
            return;
        }

        public stageResize(): void
        {
            if (this.parent) 
            {
                x = Global.stage.stageWidth / 2 + 120;
                y = Global.stage.stageHeight / 2 + 150;
            }
            return;
        }

        public hide(): void
        {
            this.stopShowTips();
            this.hideRollTips();
            return;
        }

        /* internal  */get inPeriod(): Boolean
        {
            return this._periodCount < this._periodTotal;
        }

        /* internal */ /* var */_msgs: Array<any>;

        /* internal */ /* var */_shows: Array<any>;

        /* internal */ /* var */_timer: FrameTimer;

        /* internal */ /* var */_periodCount: int;

        /* internal */ /* var */_periodTotal: int=12;

        /* internal */ /* var */_childIndex: int;

        /* internal */ /* var */_childLength: int;
    }
